package br.ufrj.cg.model;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.net.URL;

import javax.swing.ImageIcon;

public class StampImage implements Serializable{

	private static final long serialVersionUID = 1L;
	
	private String imagePath;
	private ImageIcon imageIcon;
	private int xPosition;
	private int yPosition;
	
	public StampImage()
	{
		super();
	}

	public StampImage(String paramImagePath)
	{
		super();
		imagePath = paramImagePath;
		try{
			ClassLoader classLoader = this.getClass().getClassLoader();
			URL imageURL = classLoader.getResource(imagePath);
			imageIcon = new ImageIcon(imageURL);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public StampImage(String paramImagePath, int width, int height, int x, int y)
	{
		super();
		imagePath = paramImagePath;
		xPosition = x;
		yPosition = y;
		
		try{
			ClassLoader classLoader = this.getClass().getClassLoader();
			URL imageURL = classLoader.getResource(imagePath);
			imageIcon = resize(new ImageIcon(imageURL), 128, 128);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void loadImage(String paramImagePath)
	{
		imagePath = paramImagePath;
		imageIcon = new ImageIcon(imagePath);
	}

	public ImageIcon resize(ImageIcon imageIcon, int width, int height)
	{
		Image img = imageIcon.getImage();
		BufferedImage bufferedImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = bufferedImg.createGraphics();
		
		g.drawImage(img, 0, 0, width, height, null);
		g.dispose();
		
		ImageIcon newImageIcon = new ImageIcon(bufferedImg);
		return newImageIcon;
	}
	
	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}
	
	public ImageIcon getImageIcon()
	{
		return imageIcon;
	}
	public Image getImage() {
		return imageIcon.getImage();
	}

	public void setImageIcon(ImageIcon imageIcon) {
		this.imageIcon = imageIcon;
	}

	public int getxPosition() {
		return xPosition;
	}

	public void setxPosition(int xPosition) {
		this.xPosition = xPosition;
	}

	public int getyPosition() {
		return yPosition;
	}

	public void setyPosition(int yPosition) {
		this.yPosition = yPosition;
	}

}
